//
//  DKContactAuthCell.m
//  DanKU
//
//  Created by 蓝鳍互娱 on 2023/11/27.
//

#import "DKContactAuthCell.h"
#import "DKContactAuthSigleView.h"
#import "DKContactController.h"
static NSString * DKContactAuthCellId = @"DKContactAuthCellId";
@interface DKContactAuthCell()
@property (nonatomic, strong)UIView * dk_ContactBgView;
@property (nonatomic,strong) DKContactAuthSigleView *dk_ContactAuthSigleFirstView;
@property (nonatomic,strong) DKContactAuthSigleView *dk_ContactAuthSigleSecondView;

@property (nonatomic, strong)UIButton * dk_NextBtn;
@end
@implementation DKContactAuthCell
+ (instancetype)contactAuthCell:(UITableView *)tableView{
    DKContactAuthCell * dk_ContactAuthCell = [tableView dequeueReusableCellWithIdentifier:DKContactAuthCellId];
    if (!dk_ContactAuthCell) {
        dk_ContactAuthCell = [[DKContactAuthCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DKContactAuthCellId];
    }
    dk_ContactAuthCell.backgroundColor = [UIColor clearColor];
    dk_ContactAuthCell.selectionStyle = UITableViewCellSelectionStyleNone;
    dk_ContactAuthCell.accessoryType = UITableViewCellAccessoryNone;
    return dk_ContactAuthCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    WeakSelf(self)
    self.dk_ContactBgView = [[UIView alloc] init];
    self.dk_ContactBgView.backgroundColor = [UIColor whiteColor];
    self.dk_ContactBgView.layer.cornerRadius = DK_IsWidthScale(50);
    [self.contentView addSubview:self.dk_ContactBgView];
    [self.dk_ContactBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(30)));
        make.bottom.equalTo(@(-DK_IsWidthScale(0)));
    }];
    UIView * dk_PanCardBottomView = [[UIView alloc] init];
    dk_PanCardBottomView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:dk_PanCardBottomView];
    [dk_PanCardBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.bottom.equalTo(@(-DK_IsWidthScale(0)));
    }];
    
    self.dk_ContactAuthSigleFirstView = [[DKContactAuthSigleView alloc] init];
    self.dk_ContactAuthSigleFirstView.authContactAuthSigleType = AuthContactAuthSigleTypeContactFirst;
    [self.dk_ContactBgView addSubview:self.dk_ContactAuthSigleFirstView];
    [self.dk_ContactAuthSigleFirstView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(210)));
    }];
    self.dk_ContactAuthSigleFirstView.updataScuessBlock = ^{
        [weakSelf makeNextStatus];
    };
    
    self.dk_ContactAuthSigleSecondView = [[DKContactAuthSigleView alloc] init];
    self.dk_ContactAuthSigleSecondView.authContactAuthSigleType = AuthContactAuthSigleTypeContactSecond;
    [self.dk_ContactBgView addSubview:self.dk_ContactAuthSigleSecondView];
    [self.dk_ContactAuthSigleSecondView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.top.equalTo(self.dk_ContactAuthSigleFirstView.mas_bottom).offset(DK_IsWidthScale(20));
        make.height.equalTo(@(DK_IsWidthScale(210)));
    }];
    self.dk_ContactAuthSigleSecondView.updataScuessBlock = ^{
        [weakSelf makeNextStatus];
    };
    //next
    self.dk_NextBtn = [[UIButton alloc] init];
    [self.dk_NextBtn setTitle:@"Next" forState:UIControlStateNormal];
    [self.dk_NextBtn setTitleColor:DK_Hex(@"#4566FF") forState:UIControlStateDisabled];
    [self.dk_NextBtn setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
    self.dk_NextBtn.titleLabel.font = DK_FONT_Semibold(16);
    [self.dk_NextBtn setBackgroundImage:DK_GetImage(@"dk_registerNextSelectBg") forState:UIControlStateNormal];
    [self.dk_NextBtn setBackgroundImage:DK_GetImage(@"dk_registerNextBg") forState:UIControlStateDisabled];
    self.dk_NextBtn.enabled = NO;
    [self.dk_NextBtn addTarget:self action:@selector(goCheck) forControlEvents:UIControlEventTouchUpInside];
    [self.dk_ContactBgView addSubview:self.dk_NextBtn];
    [self.dk_NextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.top.equalTo(self.dk_ContactAuthSigleSecondView.mas_bottom).offset(DK_IsWidthScale(20));
    }];
    UIButton * dk_AgreementBtn = [[UIButton alloc] init];
    [dk_AgreementBtn setTitle:@"《Privacy Agreement》" forState:UIControlStateNormal];
    [dk_AgreementBtn setTitleColor:DK_Hex(@"#CCCCCC") forState:UIControlStateNormal];
    dk_AgreementBtn.titleLabel.font = DK_FONT_Regular(12);
    [dk_AgreementBtn addTarget:self action:@selector(CheckAgreement) forControlEvents:UIControlEventTouchUpInside];
    [self.dk_ContactBgView addSubview:dk_AgreementBtn];
    [dk_AgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.dk_NextBtn.mas_bottom).offset(DK_IsWidthScale(20));
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
}
//-(void)layoutSublayersOfLayer:(CALayer *)layer{
//    [super layoutSublayersOfLayer:layer];
//    [self.dk_ContactBgView makeCornerOnTopleftRight:DK_IsWidthScale(50)];
//}
- (void)makeNextStatus{
    if(([self.dk_ContactAuthSigleFirstView getContactAuthRelation].length > 0)&&([self.dk_ContactAuthSigleFirstView getContactAuthName].length > 0)&&([self.dk_ContactAuthSigleFirstView getContactAuthMobile].length > 0)&&([self.dk_ContactAuthSigleSecondView getContactAuthRelation].length > 0)&&([self.dk_ContactAuthSigleSecondView getContactAuthName].length > 0)&&([self.dk_ContactAuthSigleSecondView getContactAuthMobile].length > 0)){
        self.dk_NextBtn.enabled = YES;
    }else{
        self.dk_NextBtn.enabled = NO;
    }
}
- (void)goCheck{
    [self requestUserBrhavRecordContact:DK_ActionClick withParmDic:@{}];
    
    NSMutableDictionary *userInfoDataDic = [[NSMutableDictionary alloc] init];
    [userInfoDataDic setObject:[self.dk_ContactAuthSigleFirstView getContactAuthMobile] forKey:@"contact1"];
    [userInfoDataDic setObject:[self.dk_ContactAuthSigleFirstView getContactAuthName] forKey:@"contact1Name"];
    [userInfoDataDic setObject:[self.dk_ContactAuthSigleSecondView getContactAuthMobile] forKey:@"contact2"];
    [userInfoDataDic setObject:[self.dk_ContactAuthSigleSecondView getContactAuthName] forKey:@"contact2Name"];
    [userInfoDataDic setObject:[self.dk_ContactAuthSigleFirstView getContactAuthRelation] forKey:@"relationship1"];
    [userInfoDataDic setObject:[self.dk_ContactAuthSigleSecondView getContactAuthRelation] forKey:@"relationship2"];
    NSMutableDictionary *userInfoDic = [[NSMutableDictionary alloc] init];
    [userInfoDic setObject:userInfoDataDic forKey:@"data"];
    [userInfoDic setObject:@"CONTACT_INFO" forKey:@"step"];
    [DKPublicHttp apiSaveUserInfoForAPI:userInfoDic complete:^{//保存用户信息
        if(self.RequestScuessContactAuthBlock){
            self.RequestScuessContactAuthBlock();
        }
        [self requestUserBrhavRecordContact:DK_ActionSave withParmDic:@{}];
    }fail:^{
        
    }];
}
- (void)CheckAgreement{
    if(self.CheckPrivateAgrmentBlock){
        self.CheckPrivateAgrmentBlock();
    }
}
- (void)requestUserBrhavRecordContact:(NSString *)action withParmDic:(NSDictionary *)parmDic{
    [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_VerifyContact withAction:action complete:^{
            
    } fail:^{
            
    }];
}
@end
